package com.vito.dcs.paver.construction.action;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.authoriza.service.SectionService;
import com.vito.base.factory.IDFactory;
import com.vito.dcs.DcsConstants;
import com.vito.dcs.paver.construction.model.DataPaverConstructionModel;
import com.vito.dcs.paver.construction.model.GpsUpData;
import com.vito.dcs.paver.construction.service.DataPaverConstructionService2;
import com.vito.dcs.sys.constructionVehicle.model.SysConstructionVehicleModel;
import com.vito.dcs.sys.constructionVehicle.service.SysConstructionVehicleService;
import com.vito.dcs.sys.deviceSet.model.DeviceSetModel;
import com.vito.dcs.sys.deviceSet.service.DeviceSetService;

/***
 * 工程车辆GPS数据上报
 * @author hug19
 *
 */
@Controller
@RequestMapping("/road-api/app/device")
public class ConstructionGpsReportAction extends BaseAction {

	private static final Logger log = LoggerFactory.getLogger(ConstructionGpsReportAction.class);

	@Reference
	private SysConstructionVehicleService sysConstructionVehicleService;

	@Reference
	private DeviceSetService deviceSetService;

	@Reference
	private DataPaverConstructionService2 dataPaverConstructionService;

	@Reference
	private SectionService sectionService;

	//private static final ConcurrentHashMap<String, Object> prevYLJDataMap = new ConcurrentHashMap<String, Object>();
	//private static final ConcurrentHashMap<String, ConcurrentHashMap<String, Object>> prevTPJDataMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, Object>>();
	
	//private static volatile Date date = null;
	
	/**
	 * 验证上报数据
	 * @param resMap
	 * @param gpsUpData
	 * @return
	 */
	private boolean validData(Map<String,Object> resMap,GpsUpData gpsUpData) {

		log.info("GpsUpData -------> : " + gpsUpData.toString());

		/**
		 * 改动后，只校验mac
		 */
		/*if(gpsUpData==null||StringUtils.isEmpty(gpsUpData.getMac())||StringUtils.isEmpty(gpsUpData.getType())||
				DcsConstants.CONSTRUC_TYPE.get(gpsUpData.getType())==null) {*/
		if(gpsUpData == null || StringUtils.isEmpty(gpsUpData.getMac())) {

			resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_INVALID_DATA);
			return false;

		}else {
			SysConstructionVehicleModel sysConstructionVehicle = new SysConstructionVehicleModel();
			sysConstructionVehicle.setDeviceVid(gpsUpData.getMac());

			/**
			 * 改动前
			 */
			//sysConstructionVehicle.setVehicleType(DcsConstants.CONSTRUC_TYPE.get(gpsUpData.getType()));

			sysConstructionVehicle = sysConstructionVehicleService.querySysConstructionVehicle2(sysConstructionVehicle);

			if(sysConstructionVehicle==null||sysConstructionVehicle.getId()==null) {
				log.info("在数据库中未找到当前mac:-----> " + gpsUpData.getMac());
				resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_UNREGISTER);
				return false;
			} else {
				gpsUpData.setConId(sysConstructionVehicle.getId());
				gpsUpData.setSectionId(sysConstructionVehicle.getSectionId());
				
				gpsUpData.setVehicleName(sysConstructionVehicle.getVehicleName());
				gpsUpData.setVehicleWidth(sysConstructionVehicle.getVehicleWidth());
				
				/**
				 * 改动后，type字段根据后台配置来定
				 */
				gpsUpData.setType(DcsConstants.CONSTRUC_TYPE_REV.get(sysConstructionVehicle.getVehicleType()));
			}
		}
		return true;
	}

	/**
	 * 登录
	 * @param gpsUpData
	 * @return
	 */
	@RequestMapping(value="login",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> login(@RequestBody GpsUpData gpsUpData) {

		Map<String,Object> resMap = Maps.newHashMap();
		try {
			if(validData(resMap,gpsUpData)) {
				/*SysConstructionVehicleModel sysConstructionVehicle = new SysConstructionVehicleModel();
				sysConstructionVehicle.setDeviceVid(gpsUpData.getMac());
				sysConstructionVehicle.setVehicleType(DcsConstants.CONSTRUC_TYPE.get(gpsUpData.getType()));
				sysConstructionVehicle = 
						sysConstructionVehicleService.querySysConstructionVehicle(sysConstructionVehicle);
				String sectionId = sysConstructionVehicle.getSectionId();*/
				Map<String,Object> contentMap = Maps.newHashMap();
				DeviceSetModel deviceSetModel = new DeviceSetModel();

				deviceSetModel.setSectionId(gpsUpData.getSectionId());

				deviceSetModel = deviceSetService.queryDeviceSetBySectionId(deviceSetModel);
				if(deviceSetModel!=null&&deviceSetModel.getId()!=null) {
					contentMap.put("heartbeat_cycle", deviceSetModel.getHeartBeatCycle());
					contentMap.put("report_cycle", deviceSetModel.getReportCycle());
				}else {
					contentMap.put("heartbeat_cycle", "0");
					contentMap.put("report_cycle", "0");
				}
				//contentMap.put("server_date",DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));

				contentMap.put("temp_min", 10);
				contentMap.put("temp_max", 300);
				contentMap.put("speed_min", 0);
				contentMap.put("speed_max", 30);

				contentMap.put("server_date",getCurrentTime());
				resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_SUCCESS);
				resMap.put("content", contentMap);
			}

			resMap.put("error", "");	

		} catch (Exception e) {
			log.error(e.getMessage());
			resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_UNKNOW_ERROR);
			//resMap.put("error", e.getMessage());
		}
		log.info("LoginResult <------ : " + resMap.toString());
		return resMap;
	}
	
	
	private DataPaverConstructionModel processEntity(GpsUpData gpsUpData){
		DataPaverConstructionModel dataPaverConstructionModel = new DataPaverConstructionModel();
		dataPaverConstructionModel.setId(IDFactory.getIDFactory().getIdInc("tbl_dcs_data_paver_construction_m")+"");

		dataPaverConstructionModel.setConId(gpsUpData.getConId());

		dataPaverConstructionModel.setCreateTime(new Date());
		dataPaverConstructionModel.setType(gpsUpData.getType());
		dataPaverConstructionModel.setMac(gpsUpData.getMac());
		dataPaverConstructionModel.setLat(gpsUpData.getLat());
		dataPaverConstructionModel.setLng(gpsUpData.getLng());
		dataPaverConstructionModel.setHeight(gpsUpData.getHeight()==null?"":gpsUpData.getHeight()+"");
		dataPaverConstructionModel.setIos(gpsUpData.getIos()==null?"":gpsUpData.getIos()+"");
		dataPaverConstructionModel.setVal1(gpsUpData.getVal_1());
		dataPaverConstructionModel.setVal2(gpsUpData.getVal_2());
		dataPaverConstructionModel.setVal3(gpsUpData.getVal_3());
		dataPaverConstructionModel.setVal4(gpsUpData.getVal_4());
		dataPaverConstructionModel.setVal5(gpsUpData.getVal_5());
		dataPaverConstructionModel.setVal6(gpsUpData.getVal_6());
		dataPaverConstructionModel.setVal7(gpsUpData.getVal_7());
		dataPaverConstructionModel.setVal8(gpsUpData.getVal_8());
		dataPaverConstructionModel.setVal9(gpsUpData.getVal_9());
		dataPaverConstructionModel.setTime(gpsUpData.getTime());
		dataPaverConstructionModel.setSatNum(gpsUpData.getSat_num()==null?null:gpsUpData.getSat_num()+"");
		dataPaverConstructionModel.setIssyc(gpsUpData.getIsSyc()==null?null:gpsUpData.getIsSyc()+"");
		dataPaverConstructionModel.setDifData(gpsUpData.getDif_data()==null?null:gpsUpData.getDif_data()+"");
		dataPaverConstructionModel.setData(gpsUpData.getData()==null?null:gpsUpData.getData()+"");
		dataPaverConstructionModel.setSeq(gpsUpData.getSeq());
		dataPaverConstructionModel.setA1(gpsUpData.getA1());
		dataPaverConstructionModel.setA2(gpsUpData.getA2());
		dataPaverConstructionModel.setA3(gpsUpData.getA3());
		dataPaverConstructionModel.setGx(gpsUpData.getGx());
		dataPaverConstructionModel.setGy(gpsUpData.getGy());
		dataPaverConstructionModel.setGz(gpsUpData.getGz());

		dataPaverConstructionModel.setIsHandler("0");
		dataPaverConstructionModel.setSectionId(gpsUpData.getSectionId());
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String format = sdf.format(gpsUpData.getTime());
		dataPaverConstructionModel.setUpTimeInd(format);
		return dataPaverConstructionModel;
	}
	
	/**
	 * 数据上报
	 * @param gpsUpData
	 * @return
	 */
	@RequestMapping(value="pushinfo",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> getData(@RequestBody GpsUpData gpsUpData) {
		Map<String,Object> resMap = Maps.newHashMap();
		try {

			if(validData(resMap,gpsUpData)) {
				
				DataPaverConstructionModel dataPaverConstructionModel = processEntity(gpsUpData);
				
				dataPaverConstructionService.save(dataPaverConstructionModel,gpsUpData);

				resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_SUCCESS);
				resMap.put("content", "success");
			}

			resMap.put("error", "");
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_UNKNOW_ERROR);
		}
		return resMap;
	}
	/**
	 * 离线数据上报
	 * @param gpsUpData
	 * @return
	 */
	@RequestMapping(value="pushpackage",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> pushPackage(@RequestParam MultipartFile[] files, HttpServletRequest request) {
		Map<String,Object> resMap = Maps.newHashMap();
		try {
			
			GpsUpData gpsUpData = new GpsUpData();
			gpsUpData.setType(request.getParameter("type"));
			gpsUpData.setMac(request.getParameter("mac"));
			
			if(validData(resMap,gpsUpData )) {
				
				if(files.length > 0){
					List<Map<String,Object>> list = new ArrayList<>();
					try {
						for (MultipartFile file : files) {
							
							if(file.getSize() > 0){
								File deCompressGZFile = deCompressGZFile(file.getInputStream(), request);
								List<Map<String, Object>> deCompressGZFileFinish = deCompressGZFileFinish(deCompressGZFile);
								list.addAll(deCompressGZFileFinish);
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					} 
					if(list.size() > 0){
						
						log.info("压缩文件解压后总条数：-----> " + list.size());
						
						for (int i = 0; i < list.size(); i ++) {
							Map<String,Object> map = list.get(i);
							log.info("压缩文件待处理数据：-----> 第  " + i + " 条数据  -----> " + map.toString());
							
							packGpsData(gpsUpData, map);
							
							DataPaverConstructionModel dataPaverConstructionModel = processEntity(gpsUpData);
							dataPaverConstructionService.save(dataPaverConstructionModel,gpsUpData);
						}
					}
				}
				resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_SUCCESS);
				resMap.put("content", "success");
			}
			
			resMap.put("error", "");
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_UNKNOW_ERROR);
		}
		return resMap;
	}
	
	/**
	 * 将解析后的Map数据封装为Model对象
	 * @param gpsUpData
	 * @param map
	 * @throws ParseException
	 */
	private void packGpsData(GpsUpData gpsUpData, Map<String, Object> map) throws ParseException {
		gpsUpData.setLng(Double.parseDouble(map.get("lng").toString()));
		gpsUpData.setLat(Double.parseDouble(map.get("lat").toString()));
		gpsUpData.setHeight(Double.parseDouble(map.get("height").toString()));
		gpsUpData.setIos(Double.parseDouble(map.get("ios").toString()));
		gpsUpData.setVal_1((String) map.get("val_1"));
		gpsUpData.setVal_2((String) map.get("val_2"));
		gpsUpData.setVal_3((String) map.get("val_3"));
		gpsUpData.setVal_4((String) map.get("val_4"));
		gpsUpData.setVal_5((String) map.get("val_5"));
		gpsUpData.setVal_6((String) map.get("val_6"));
		gpsUpData.setVal_7((String) map.get("val_7"));
		gpsUpData.setVal_8((String) map.get("val_8"));
		gpsUpData.setVal_9((String) map.get("val_9"));
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		gpsUpData.setTime(sdf.parse((String) map.get("time")));
		gpsUpData.setIsSyc(Integer.parseInt(map.get("isSyc").toString()));
		gpsUpData.setSat_num(Integer.parseInt(map.get("sat_num").toString()) );
		gpsUpData.setDif_data(Integer.parseInt(map.get("dif_data").toString()) );
		gpsUpData.setData(Integer.parseInt(map.get("data").toString()));
		gpsUpData.setSeq((String) map.get("seq"));
		if(map.get("A1") == null){
			gpsUpData.setA1(null);
		} else {
			gpsUpData.setA1(Double.parseDouble(map.get("A1").toString()));
		}
		if(map.get("A2") == null){
			gpsUpData.setA2(null);
		} else {
			gpsUpData.setA2(Double.parseDouble(map.get("A2").toString()));
		}
		if(map.get("A3") == null){
			gpsUpData.setA3(null);
		} else {
			gpsUpData.setA3(Double.parseDouble(map.get("A3").toString()));
		}
		if(map.get("Gx") == null){
			gpsUpData.setGx(null);
		} else {
			gpsUpData.setGx(Double.parseDouble(map.get("Gx").toString()));
		}
		if(map.get("Gy") == null){
			gpsUpData.setGy(null);
		} else {
			gpsUpData.setGy(Double.parseDouble(map.get("Gy").toString()));
		}
		if(map.get("Gz") == null){
			gpsUpData.setGz(null);
		} else {
			gpsUpData.setGz(Double.parseDouble(map.get("Gz").toString()));
		}
	}
	
	/**
	 * 解压Gzip文件
	 * @param fin
	 * @param request
	 * @return
	 */
	private static File deCompressGZFile(InputStream fin,HttpServletRequest request) {
		FileOutputStream out = null;
		GzipCompressorInputStream gzIn = null;
		try {
			BufferedInputStream in = new BufferedInputStream(fin);
			
			String str = request.getServletContext().getRealPath("/")+"WEB-INF\\";
			File outFile = new File(str + getExtString());
			
			out = new FileOutputStream(outFile);
			gzIn = new GzipCompressorInputStream(in);
			final byte[] buffer = new byte[2048];
			int n = 0;
			while (-1 != (n = gzIn.read(buffer))) {
				out.write(buffer, 0, n);
			}
			return outFile;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			try {
				out.close();
				gzIn.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 处理解压后的文件
	 * @param file
	 * @return
	 */
	private static List<Map<String,Object>> deCompressGZFileFinish(File file) {
		
		List<Map<String,Object>> list = new ArrayList<>();
		
		FileInputStream is = null;
		InputStreamReader isr = null;
		BufferedReader br = null;
		try {
			is = new FileInputStream(file);
			isr = new InputStreamReader(is);
			br = new BufferedReader(isr);
			String str = "";
			while((str = br.readLine()) != null ){
				@SuppressWarnings("unchecked")
				Map<String,Object> map = (Map<String, Object>) JSONObject.parse(str);
				if(map != null){
					list.add(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
				isr.close();
				is.close();
				file.delete();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return list;
	}
	
	/**
	 * 构建随机文件名
	 * @return
	 */
	private static String getExtString(){
		long currentTimeMillis = System.currentTimeMillis();
		Random r = new Random();
		int nextInt = r.nextInt(10000);
		return currentTimeMillis + "" + nextInt;
	}
	/**
	 * 数据上报2  ---> 优化后
	 * @param gpsUpData
	 * @return
	 */
	@RequestMapping(value="pushinfo2",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> getData2(@RequestBody GpsUpData gpsUpData) {
		Map<String,Object> resMap = Maps.newHashMap();
		try {

			if(validData(resMap,gpsUpData)) {

				DataPaverConstructionModel dataPaverConstructionModel = new DataPaverConstructionModel();
				dataPaverConstructionModel.setId(IDFactory.getIDFactory().getIdInc("tbl_dcs_data_paver_construction_m")+"");

				dataPaverConstructionModel.setConId(gpsUpData.getConId());

				dataPaverConstructionModel.setCreateTime(new Date());
				dataPaverConstructionModel.setType(gpsUpData.getType());
				dataPaverConstructionModel.setMac(gpsUpData.getMac());
				dataPaverConstructionModel.setLat(gpsUpData.getLat());
				dataPaverConstructionModel.setLng(gpsUpData.getLng());
				dataPaverConstructionModel.setHeight(gpsUpData.getHeight()==null?"":gpsUpData.getHeight()+"");
				dataPaverConstructionModel.setIos(gpsUpData.getIos()==null?"":gpsUpData.getIos()+"");
				dataPaverConstructionModel.setVal1(gpsUpData.getVal_1());
				dataPaverConstructionModel.setVal2(gpsUpData.getVal_2());
				dataPaverConstructionModel.setVal3(gpsUpData.getVal_3());
				dataPaverConstructionModel.setVal4(gpsUpData.getVal_4());
				dataPaverConstructionModel.setVal5(gpsUpData.getVal_5());
				dataPaverConstructionModel.setVal6(gpsUpData.getVal_6());
				dataPaverConstructionModel.setVal7(gpsUpData.getVal_7());
				dataPaverConstructionModel.setVal8(gpsUpData.getVal_8());
				dataPaverConstructionModel.setVal9(gpsUpData.getVal_9());
				dataPaverConstructionModel.setTime(gpsUpData.getTime());
				dataPaverConstructionModel.setSatNum(gpsUpData.getSat_num()==null?null:gpsUpData.getSat_num()+"");
				dataPaverConstructionModel.setIssyc(gpsUpData.getIsSyc()==null?null:gpsUpData.getIsSyc()+"");
				dataPaverConstructionModel.setDifData(gpsUpData.getDif_data()==null?null:gpsUpData.getDif_data()+"");
				dataPaverConstructionModel.setData(gpsUpData.getData()==null?null:gpsUpData.getData()+"");
				dataPaverConstructionModel.setSeq(gpsUpData.getSeq());
				dataPaverConstructionModel.setA1(gpsUpData.getA1());
				dataPaverConstructionModel.setA2(gpsUpData.getA2());
				dataPaverConstructionModel.setA3(gpsUpData.getA3());
				dataPaverConstructionModel.setGx(gpsUpData.getGx());
				dataPaverConstructionModel.setGy(gpsUpData.getGy());
				dataPaverConstructionModel.setGz(gpsUpData.getGz());

				dataPaverConstructionModel.setIsHandler("0");
				dataPaverConstructionModel.setSectionId(gpsUpData.getSectionId());

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String format = sdf.format(gpsUpData.getTime());
				dataPaverConstructionModel.setUpTimeInd(format);

				//dataPaverConstructionModel.setUpTimeInd(DateUtils.format(gpsUpData.getTime(), "yyyy-MM-dd"));


				if("2".equals(dataPaverConstructionModel.getData()) || "4".equals(dataPaverConstructionModel.getData())
						|| "5".equals(dataPaverConstructionModel.getData())){

					dataPaverConstructionModel.setIsRight("0");

				} else {
					dataPaverConstructionModel.setIsRight("1");
				}

				//dataPaverConstructionService.save(dataPaverConstructionModel);

				resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_SUCCESS);
				resMap.put("content", "success");
			}

			resMap.put("error", "");
		} catch (Exception e) {
			log.error(e.getMessage());
			resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_UNKNOW_ERROR);
			//resMap.put("error", e.getMessage());
		}
		log.info("PushinfoResult <------ : " + resMap.toString());
		return resMap;
	}

	/**
	 * 心跳检测
	 * @param gpsUpData
	 * @return
	 */
	@RequestMapping(value="heartbeat",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> heartBeat(@RequestBody GpsUpData gpsUpData) {
		Map<String,Object> resMap = Maps.newHashMap();
		try {

			if(validData(resMap,gpsUpData)) {

				if(StringUtils.isEmpty(gpsUpData.getState())||DcsConstants.CONSTRUC_GPS_STATE_NO_WORK.equals(
						gpsUpData.getState())||DcsConstants.CONSTRUC_GPS_STATE_FAULT.equals(gpsUpData.getState())) {
					resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_SYNC);
					resMap.put("error", "需要同步时间");
					//resMap.put("content", DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
					resMap.put("content", getCurrentTime());
				}else {
					resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_SUCCESS);
					resMap.put("error", "");
				}
			}

		} catch (Exception e) {
			log.error(e.getMessage());
			resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_UNKNOW_ERROR);
			//resMap.put("error", e.getMessage());
		}
		log.info("HeartbeatResult <------ : " + resMap.toString());
		return resMap;
	}

	private static String getCurrentTime(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String format2 = sdf.format(new Date());
		return format2;
	} 

	/**
	 * 指令确认
	 * @param gpsUpData
	 * @return
	 */
	@RequestMapping(value="response",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> responseGps(@RequestBody GpsUpData gpsUpData) {
		Map<String,Object> resMap = Maps.newHashMap();
		try {
			if(validData(resMap,gpsUpData)) {
				resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_SUCCESS);
				resMap.put("error", "");
			}
		}catch (Exception e) {
			log.error(e.getMessage());
			resMap.put("code", DcsConstants.CONSTRUC_GPS_CODE_UNKNOW_ERROR);
			//resMap.put("error", e.getMessage());
		}
		log.info("ResponseResult <------ : " + resMap.toString());
		return resMap;

	}
	
	/**
	 * 通过温度计算离析值
	 * @param gpsUpData
	 * @return
	 */
	@SuppressWarnings("unused")
	private static String processTemp2Segregation(GpsUpData gpsUpData){

		List<Double> list = new ArrayList<Double>();

		if(!"error".equals(gpsUpData.getVal_1()) && !"null".equals(gpsUpData.getVal_1())){
			list.add(Double.parseDouble(gpsUpData.getVal_1()));
		} 
		if(!"error".equals(gpsUpData.getVal_2()) && !"null".equals(gpsUpData.getVal_2())){
			list.add(Double.parseDouble(gpsUpData.getVal_2()));
		}
		if(!"error".equals(gpsUpData.getVal_3()) && !"null".equals(gpsUpData.getVal_3())){
			list.add(Double.parseDouble(gpsUpData.getVal_3()));
		} 
		if(!"error".equals(gpsUpData.getVal_4()) && !"null".equals(gpsUpData.getVal_4())){
			list.add(Double.parseDouble(gpsUpData.getVal_4()));
		}
		if(!"error".equals(gpsUpData.getVal_5()) && !"null".equals(gpsUpData.getVal_5())){
			list.add(Double.parseDouble(gpsUpData.getVal_5()));
		}

		Collections.sort(list);
		if(list.size() > 0){
			return (list.get(list.size()-1) - list.get(0))+"";
		}
		return 0.0+"";
	}
	
}
